package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    @GetMapping("/userInfo")
    public ResponseEntity userInfo(String huanxinId){
        UserInfoVo vo=messagesService.findByUserInfo(huanxinId);
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Long friendId = Long.valueOf(map.get("userId").toString());
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/contacts")
    public ResponseEntity contactsPage(@RequestParam(defaultValue = "1") int page,
                                       @RequestParam(defaultValue = "10") int pagesize,
                                       String keyword){
        PageResult pr=messagesService.contactsPage(page,pagesize,keyword);
        return ResponseEntity.ok(pr);
    }

    /**
     * 用户点赞列表
     */
    @GetMapping("likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messagesService.likes(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 用户评论列表
     */
    @GetMapping("comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messagesService.comments(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 用户喜欢列表
     */
    @GetMapping("loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messagesService.loves(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查询公告列表
     */
    @GetMapping("announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messagesService.announcements(page,pagesize);
        return ResponseEntity.ok(pr);
    }

}